<?php
include_once('common/header.php');
if($AppUI->id > 0) {
	Vfriend_Function::redirect(HOST_VFRIEND);
}
$strEmail 	= $objRequest->getParam('pgcaemail', '');
$strCaptcha	= $objRequest->getParam('pcaptcha', '');
$intError	= 0;
if($strEmail == "" || $strCaptcha == "")
	$intError = 8;
elseif(!Vfriend_Captcha_Image::validate($strCaptcha)) {
	$intError = 2;
}
if($intError == 0) {
	$objVfriendUser = new Vfriend_User();
	$objUser		= $objVfriendUser->getInfoByEmail($strEmail);
	if($objUser) {
		if($objUser->statuses == 0 && $objUser->code != '') {
			$intHexUserId 	= $objUser->hex;
			$strCode		= $objUser->code;
			$intExpireTime	= time() + (24*60*60*ACTIVE_EXPIRE_TIME);
			// send
			$this->view->strCode		= $strCode;
			$this->view->intHexUserId	= Vfriend_Function::base64E($intHexUserId);
			$this->view->intExpireTime	= Vfriend_Function::base64E($intExpireTime);
			$strSubject		= INDEX_GETCODE_ACCOUNT_SUB;
			$objView 		= Zend_Registry::get('objView'); 
			$strContent 	= $objView->fetch('email/getcode-account.tpl');
			$objMail		= new Vfriend_Mail();
			$intSend		= $objMail->send(EMAIL_NOREPLY, EMAIL_NOREPLY_NAME, $strEmail, $strSubject, $strContent);
			if($intSend)
				Vfriend_Function::redirect(LINK_INDEX_ACT_HELP . '?userid=' . $intHexUserId . '&gc=1');
			else
				$intError = 3;
		}
		else 
			$intError 	= 7;
		
	}
	else
		$intError 	= 6;
}
if($intError > 0) {
	$_SESSION['pgcaemail']	= $strEmail;
	Vfriend_Function::redirect(LINK_INDEX_GETCODE_ACCOUNT . '?err=' . $intError);
}

?>